let db = require('../db/index')

exports.get = (req,res) =>{//通过key查询数据
    var sql = "select * from cookie where cokey like '%' ?"
    db.query(sql,[req.query.cokey],(err,data)=>{
        if(err){
            return res.send('错误：' +err.message)
        }
        res.send(data)
    })
}

exports.del = (req,res) =>{//通过key删除数据
    var sql = 'delete from cookie where cokey = ?'
    db.query(sql,[req.query.cokey],(err,data) =>{
        if(err){
            return res.send('错误：' +err.message)
        }
        res.send(data)
    })

}

exports.add = (req,res)=>{
    var sql = 'insert into cookie (cokey,value,id) values (?,?,?)'
    db.query(sql, [req.query.cokey, req.query.value, req.query.id],(err,data)=>{
        if(err){
            return res.send('错误：'+err.message)
        }
        res.send(data)
    })
}

exports.update = (req,res)=>{
    var sql = 'update cookie set cokey = ?, value = ? where id = ?'
    db.query(sql, [req.query.cokey,req.query.value,req.query.id],(err,data)=>{
        if(err){
            return res.send('错误：'+err.message)
        }
        res.send(data)
    })
}